<template>
  <div class="app-container clearfix">  
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="关键字" prop="symbol">
          <el-input v-model="filterForm.keyword" clearable placeholder="合约" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
      </el-form>
      <el-button @click="handleFilter()">搜索</el-button>
    </div>
      <el-table
      :data="list"
      border
      style="width: 100%">
    </el-table-column>
      <el-table-column
        label="合约">
        <template slot-scope="{row}">
          <div>{{ row.futuresName }}</div>
          <div>{{ row.code }} <i class="el-icon-copy-document"></i></div>
        </template>
      </el-table-column>
      <el-table-column
        label="趋势1">
        <template slot-scope="{row}">
          <el-tag
            effect="danger" v-if="row.direction == 1">
            看多
          </el-tag>
                  <el-tag
            effect="success" v-else-if="row.direction == 2">
            看空
          </el-tag>
                  <el-tag
            effect="info" v-else>
            未明确
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="趋势2">
        <template slot-scope="{row}">
          <el-tag
            effect="danger" v-if="row.mainDirection == 1">
            看多
          </el-tag>
                  <el-tag
            effect="success" v-else-if="row.mainDirection == 2">
            看空
          </el-tag>
                  <el-tag
            effect="info" v-else>
            未明确
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="持仓">
        <template slot-scope="{row}">
          <div>{{ row.position }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="最新价格">
        <template slot-scope="{row}">
          <div>{{ row.closePrice }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="成交量">
        <template slot-scope="{row}">
          <div>{{ row.volume }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="成交额">
        <template slot-scope="{row}">
          <div>{{ row.amount }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="上市时间" width="140">
        <template slot-scope="{row}">
          <span>{{ row.market_date }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="到期时间" width="100">
        <template slot-scope="{row}">
          <div>{{ row.expire_date }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="看涨">
        <template slot-scope="{row}">
          <div>{{ row.fallWeight }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="看跌">
        <template slot-scope="{row}">
          <div>{{ row.riseWeight }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="三十日波动"
        width="100">
        <template slot-scope="{row}">
          <div>{{ row.thirtyDayWeight }}%</div>
        </template>
      </el-table-column>
      <el-table-column
        label="最后更新"
        width="160">
        <template slot-scope="{row}">
          <span>{{ row.updatedAt }}</span>
        </template>
      </el-table-column>
      </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getSymbol} from '@/utils/symbol' // secondary package based on el-pagination
import {getContractList,copyFutures, removeFutures} from '@/api/knowledge/futures'



export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"600",
      total: 0,
      listLoading: false,
      documentationList:[],
      connected:"loading",
      timer:null,
      filterForm: {
        page: 1,
        size: 10,
        localSymbol:"",
        status:5,
        style:"0",
        keyword: undefined
      }
    }
  },
  created() {
    let symbolData = getSymbol()
    try {
      this.filterForm.localSymbol = symbolData.code
    } catch (error) {
      
    }
    this.getList()
  },
  destroyed () {
      // 销毁监听
      this.close()
      clearInterval(this.timer)
      console.log("清除定时器")
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getContractList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleSubscribeRemove:function(futures){
      let _this = this;
      removeFutures({
        "futuresID":futures.ID
      }).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.getList()
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleCreate:function(){
        this.$router.push({ path: 'futures-add'})
    },
    handleUpdate:function(futuresID){
        this.$router.push({ path: 'futures-add', query: { 'futuresID': futuresID }})
    },
    handleCopy:function(futuresID){
      let _this = this;
      console.log("期权",_this.filterForm)
      copyFutures({
        "futuresID":futuresID
      }).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.getList()
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange:function(){

    }
  }
}
</script>
<style>
.filter { float: left; width: 160px; padding: 20px; min-height: 600px; }
.article { float: left; width: 800px; }
.article-item { width: 800px; height: 200px; margin-right: 25px; }
.article-item-text { float: left; width:600px; }
.article-item-icon { float: right; width:200px; height:150px; padding-left: 50px; }
.article-item-icon img { width:100%; height:100%; border-radius: 10px; }
</style>